{extend name="lib/common_list" /}
{block name="title"}{/block}
{block name="css"}
{load href="/static/sys/css/common.css" /}
{load href="/static/plugins/select2/css/select2.css" /}
{load href="/static/plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker.css" /}

{load href="/static/sys/css/skin_0.css" /}
<style>
    .upfile i{padding-right:3px !important;}
    .file{ position:absolute;right:0;top:0;width:100px;height:100px;opacity:0; ilter:alpha(opacity=0);cursor:pointer;margin-bottom: 0px;margin-right: 0px; }
</style>
{/block}
{block name="javascript"}
{load  href="/static/plugins/select2/js/select2.js" /}
{load  href="/static/plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js" /}
{load  href="/static/plugins/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js" /}

<script>
    $(document).ready(function () {
        $("#ok").bind("click", Save);
        $("#cancel").bind("click", function () {
            parent.layer.close(parent.layer_edit_index);
        });

        /**
         * 保存内容
         */
        function Save() {
            var load_index = layer.load(0, { shade: false });

            $.ajax({
                type: 'POST',
                url: "{:url('applet_img/edit')}",
                data: $("#fmNew").serialize(),
                dataType: 'json',
                success: function (data) {
                    if (data.code == 1) {
                        layer.close(load_index);
                        layer.alert(data.msg, function () {
                            parent.refreshtb();
                            //window.close();
                            parent.layer.close(parent.layer_edit_index);
                        });
                    } else {
                        layer.alert(data.msg);
                    }
                }
            })
        }

        $('#applet_name').select2();

    });

    /**
     * 新增图片
     */
    var layer_image_add;
    function appletImg() {
        layer_image_add = layer.open({
            type: 2,
            title: "新增图片",
            area: ['70%', '90%'],
            content: "{:url('upload/image')}?tag=applet_img"
        })
    }

    // 上传成功后的回调，该函数名不能写错
    function getImageUrl(res) {
        if (res.tag == 'applet_img') {
            $('#applet_img').val(res.url);
            $('#previewImg_applet').attr('src', res.url);
        }
    }

    function appletValue() {
        var applet_id = $("#applet_name").children('option:selected').attr('applet_id');
        var original_id = $("#applet_name").children('option:selected').attr('original_id');
        var applet_app_id = $("#applet_name").children('option:selected').attr('applet_app_id');

        $('#applet_id').val(applet_id);
        $('#original_id').val(original_id);
        $('#applet_app_id').val(applet_app_id);
    }

</script>
{/block}

{block name="content"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form method="post" id="fmNew" class="form-horizontal" enctype="multipart/form-data">

                        <div class="form-group">
                            <label class="col-sm-2 control-label">小程序名称：</label>
                            <div class="col-sm-8">
                                <select class="form-control" name="applet_name" id="applet_name" onchange="appletValue()">
                                    <option value="">请选择...</option>
                                    {volist name="applet_list" id="v"}
                                    <option value="{$v.applet_name}" applet_id="{$v.applet_app_id}" original_id="{$v.original_id}" applet_app_id="{$v.real_app_id}" {if($v.applet_name==$Rs['applet_name'])} selected {/if}>{$v.applet_name}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">小程序ID：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="applet_id" id="applet_id" value="{$Rs['applet_id']}" readonly>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">原始ID：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="original_id" id="original_id" value="{$Rs['original_id']}" readonly>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">APP ID：</label>
                            <div class="col-sm-8">
                                <input type="number" class="form-control" name="applet_app_id" id="applet_app_id" value="{$Rs['applet_app_id']}" readonly>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">小程序头像：</label>

                            <div class="col-sm-1">
                                <span class="btn btn-primary btn-sm" style="margin-bottom:0;padding:6px 8px;" onclick="appletImg()">
                                    <i class="glyphicon glyphicon-folder-open" style="padding-right:3px;"></i> 小程序头像<input type="hidden" name="applet_img" id="applet_img" value="{$Rs['applet_img']}" />
                                </span>
                            </div>
                            <div class="col-sm-1">
                                <img id="previewImg_applet" style="height:34px;float: right;" src="{$Rs['applet_img']}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>


                        <div class="form-group">
                            <label class="col-sm-2 control-label">审核状态：</label>
                            <div class="col-sm-8">
                                <select class="form-control" name="status">
                                    {volist name="status_list" id="v"}
                                    <option value="{$key}" {if ($key == $Rs['status'])} selected {/if}>{$v}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div id = 'hidden_input'>
                            <input name="id" value="{$Rs['id']}" type="hidden"/>
                        </div>
                        <div id="dg" style="z-index: 9999; position: fixed ! important; right: 50%; top:90%;">
                            <div class="form-group">
                                <div class="col-sm-12 col-sm-offset-5" >
                                    <button class="btn btn-primary" id="ok" type="button">提交</button>
                                    <button class="btn btn-white" id="cancel" type="button">取消</button>
                                </div>
                            </div>
                        </div>

                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}